﻿using NUnit.Framework;
using Rhino.Mocks;
using SimpleServiceBus.Bus;
using SimpleServiceBus.Bus.MessageManagement.Callbacks;
using SimpleServiceBus.Bus.Pipeline;
using SimpleServiceBus.Bus.Pipeline.PipelineComponents;
using SimpleServiceBus.Tests.Stubs;

namespace SimpleServiceBus.Tests.Bus.Pipeline.PipelineComponents
{
    [TestFixture]
    public class LocalCallbackDispatcherComponentTestFixture
    {
        [Test]
        public void Will_Call_Callback_Manager_On_Process()
        {
            var comp = new LocalCallbackDispatcherComponent();
            var pipeline = MockRepository.GenerateStub<IMessagePipeline>();

            var env = new MessageEnvelope {Body = "Hello", CorrelationID = "123"};

            var context = new ServiceLocatorOnlyMessageContext();

            var mgr = MockRepository.GenerateStub<ICorrelatedCallbackManager>();
            context.RegisterService<ICorrelatedCallbackManager>(mgr);

            pipeline.Stub(action => action.CurrentContext).Return(context);

            //mgr.Stub(action => action.Notify(env.CorrelationID, env));

            comp.Pipeline = pipeline;
            comp.ProcessMessage(env);

            mgr.AssertWasCalled(action => action.Notify(env.CorrelationID, env.Body));
        }
    }
}